package com.wms.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wms.entity.BaseSupplier;
import com.wms.entity.BaseSupplierDTO;
import com.wms.entity.DialogFormDTO;
import com.wms.service.impl.BaseSupplierServiceImpl;
import com.wms.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author Ayases
 * @Date 2025/4/27 20:22
 * @Desc
 */
@RestController
@RequestMapping("/base/supplier")
public class BaseSupplierController {
    @Autowired
    private BaseSupplierServiceImpl baseSupplierServiceImpl;

    /**
     * 分页查询全部供应商信息
     */
    @GetMapping("/page")
    public R findAll(BaseSupplierDTO baseSupplierDTO) {
        PageHelper.startPage(baseSupplierDTO.getPageNum(), baseSupplierDTO.getPageSize());
        List<BaseSupplier> list = baseSupplierServiceImpl.findAll(baseSupplierDTO);
        PageInfo<BaseSupplier> pageInfo = new PageInfo<>(list);
        return R.ok(pageInfo);
    }
    /**
     * 根据id删除一条记录
     */
    @GetMapping("/deleteOne")
    public R deleteOne(BaseSupplierDTO baseSupplierDTO) {
        baseSupplierServiceImpl.deleteOne(baseSupplierDTO.getSupplierId());
        return R.ok();
    }
    /**
     * 批量删除记录
     */
    @GetMapping("/deleteBatch")
    public R deleteBatch(BaseSupplierDTO baseSupplierDTO) {
        baseSupplierServiceImpl.deleteBatch(baseSupplierDTO.getSelectedIds());
        return R.ok();
    }
    /**
     * 禁用记录
     */
    @GetMapping("/forbid")
    public R forbid(BaseSupplierDTO baseSupplierDTO) {
        baseSupplierServiceImpl.forbid(baseSupplierDTO.getSupplierId());
        return R.ok();
    }
    /**
     * 启用记录
     */
    @GetMapping("/enable")
    public R active(BaseSupplierDTO baseSupplierDTO) {
        baseSupplierServiceImpl.enable(baseSupplierDTO.getSupplierId());
        return R.ok();
    }
    /**
     * 新增记录
     */
    @GetMapping("/save")
    public R save(DialogFormDTO dialogFormDTO) {
        baseSupplierServiceImpl.save(dialogFormDTO);
        return R.ok();
    }
    /**
     * 修改记录
     */
    @GetMapping("/update")
    public R update(DialogFormDTO dialogFormDTO) {
        baseSupplierServiceImpl.update(dialogFormDTO);
        return R.ok();
    }

    /**
     * 查询全部供应商名字
     */
    @GetMapping("/namelist")
    public R findName() {
        List<String> supplierNames = baseSupplierServiceImpl.findName();
        return R.ok(supplierNames);
    }
}
